package com.链表;


public class ListNode {
     int val;
     ListNode next;
    public ListNode(int val){
        this.val = val;
    }
    public ListNode(int[] number){
        if(number.length ==0 || number == null){
            throw new RuntimeException("数组为空");
        }
        this.val = number[0];
        ListNode cur = this;
        for(int i = 1;i<number.length;i++){
            cur.next = new ListNode(number[i]);
            cur = cur.next;
        }
    }



    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();

        ListNode cur = this;
        while (cur != null){
            builder.append(cur.val);
            builder.append("->");
            cur = cur.next;
        }
        return builder.toString();
    }
}
